package com.yh.csx.bsf.ods.utils;

import com.yh.csx.bsf.core.util.ContextUtils;
import com.yh.csx.bsf.core.util.LogUtils;
import com.yh.csx.bsf.core.util.PropertyUtils;
import com.yh.csx.bsf.health.base.EnumWarnType;
import com.yh.csx.bsf.health.base.Message;
import com.yh.csx.bsf.health.warn.WarnProvider;

/**
 * 报警工具类
 * 
 * @author Robin.Wang
 * @date 2020-07-11
 */
public class WarnUtils {
	/***
	 * 
	 * 发送报警
	 */
	public static void alarm(String title, String msg, Throwable exp) {
		
		if (PropertyUtils.getPropertyCache("bsf.message.dingding.enabled", true)) {
			WarnProvider dingding = ContextUtils.getBean(WarnProvider.class, true);
				Message message = new Message();
				message.setTitle(title);
				if(exp!=null) {
					message.setContent(msg+",Exception:"+ exp.getMessage());
				}
				else {
					message.setContent(msg);
				}				
				message.setWarnType(EnumWarnType.WARN);
				dingding.notify(message);
				LogUtils.warn(WarnUtils.class, "ods", msg+"报警发送");
			}
	}
}
